package com.pucong.gitee.database.backup.business.service.controller;

import com.pucong.gitee.database.backup.business.service.service.ServiceComputerService;
import com.pucong.gitee.database.backup.common.entity.service.ServiceComputer;
import com.pucong.gitee.database.backup.common.entity.service.dto.ServiceComputerContnectTestDto;
import com.pucong.gitee.database.backup.common.entity.service.dto.ServiceComputerSaveDto;
import com.pucong.gitee.database.backup.utils.Res;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/backup/service")
@Api(tags = "8. 远程控制服务器维护 API")
public class ServiceComputerController {

    @Autowired
    private ServiceComputerService serviceComputerService;

    @GetMapping("/getServiceComputeById/{id}")
    @ApiOperation(value = "根据主键查询", notes = "根据主键查询")
    public Res<ServiceComputer> getServiceComputeById(@ApiParam("主键")@PathVariable("id") String id){
        ServiceComputer serviceComputer = serviceComputerService.getServiceComputeById(id);
        return Res.ok(serviceComputer);
    }

    @PostMapping("/saveSourceInfo")
    @ApiOperation(value = "新增和修改数据库信息")
    public Res<Integer> addBaseInfo(@Validated @RequestBody ServiceComputerSaveDto dto){
        int i = serviceComputerService.saveBaseInfo(dto);
        return Res.ok(i);
    }

    @PostMapping("/connectTest")
    @ApiOperation(value = "连接测试")
    public Res<Boolean> connectTest(@Validated @RequestBody ServiceComputerContnectTestDto dto){
        Boolean i = serviceComputerService.connectTest(dto);
        return Res.ok(i);
    }
}
